package com.cskaoyan.market.controller;


import com.cskaoyan.market.constrain.LegalOrder;
import com.cskaoyan.market.constrain.LegalSort;
import com.cskaoyan.market.db.domain.MarketStorage;
import com.cskaoyan.market.group.Update;
import com.cskaoyan.market.service.AdminStorageService;
import com.cskaoyan.market.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.util.List;

/**
 * @author lixianbiao
 * @since 2024/06/27 20:10
 */
@RestController()
@RequestMapping("admin/storage")
@Validated
public class AdminStorageController {
    @Autowired
    private AdminStorageService storageService;

    @PostMapping("create")
    public Object create(MultipartFile file) throws IOException {
        MarketStorage marketStorage = storageService.create(file);
        return ResponseUtil.ok(marketStorage);
    }

    @GetMapping("list")
    public Object list(@NotNull int page, @NotNull int limit, @LegalSort({"add_time"}) String sort, @LegalOrder String order, String name, String key){
        List<MarketStorage> marketStorages = storageService.list(page,limit,sort,order,key,name);
        return ResponseUtil.okList(marketStorages);
    }

}